﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using NinjaToolbox.PhysicsSystem;

namespace NinjaToolbox.BattleSystem
{
    public class BattleObject_AttachCollider : MonoBehaviour
    {
        public event Action<BattleObject_AttachCollider, PhysicsObject> OnTriggerEnterCallback;
        public event Action<BattleObject_AttachCollider, PhysicsObject> OnTriggerStayCallback;
        public event Action<BattleObject_AttachCollider, PhysicsObject> OnTriggerExitCallback;

        public PhysicsObject physicsObject;

        BattleObject mBoundBattleObject;
        public BattleObject BoundBattleObject { get { return mBoundBattleObject; } }


        void Awake()
        {
            physicsObject.OnTriggerEnter += onTriggerEnterCallback;
            physicsObject.OnTriggerStay += onTriggerStayCallback;
            physicsObject.OnTriggerExit += onTriggerExitCallback;
        }

        void OnDestroy()
        {
            physicsObject.OnTriggerEnter -= onTriggerEnterCallback;
            physicsObject.OnTriggerStay -= onTriggerStayCallback;
            physicsObject.OnTriggerExit -= onTriggerExitCallback;
        }

        public void BindToBattleObject(BattleObject battleObject)
        {
            mBoundBattleObject = battleObject;
        }

        void onTriggerEnterCallback(PhysicsObject sender, PhysicsObject other)
        {
            if (OnTriggerEnterCallback != null)
                OnTriggerEnterCallback(this, other);
        }

        void onTriggerStayCallback(PhysicsObject sender, PhysicsObject other)
        {
            if (OnTriggerStayCallback != null)
                OnTriggerStayCallback(this, other);
        }

        void onTriggerExitCallback(PhysicsObject sender, PhysicsObject other)
        {
            if (OnTriggerExitCallback != null)
                OnTriggerExitCallback(this, other);
        }
    }
}
